package com.accp.demo.controller.purchase;


import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.request;

import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import com.accp.demo.pojo.purchase.PurchaseOutStorage;
import com.accp.demo.pojo.purchase.PurchaseOutStorageInfo;
import com.accp.demo.service.purchase.PurchaseOutStorageService;
import com.accp.demo.pojo.PageBean;

@RestController
@RequestMapping("/purchaseOutStorage/")
public class PurchaseOutStorageController {

	@Autowired
	private PurchaseOutStorageService purchaseOutStorageService;

	@RequestMapping("query")
	@ResponseBody
	public Object query(@RequestParam Map<String,Object> map) {			
		return purchaseOutStorageService.query(map);
	}
	
	

	@RequestMapping(value="insert",method=RequestMethod.POST)
	@ResponseBody
	public void insert(@RequestBody PurchaseOutStorage pojo) {
		System.out.println(pojo);
		pojo.setLogicState(1);
		purchaseOutStorageService.insert(pojo);
	}
	
	
	@RequestMapping("queryCount")
	@ResponseBody
	public Integer queryCount() {
		return purchaseOutStorageService.getCount();
	}
	
	
	@RequestMapping("update")
	@ResponseBody
	public void update(@RequestBody PurchaseOutStorage pojo) {
//		 pojo = new PurchaseOutStorage("1001", 1, "2017-05-22", "20170519001", 1, "RMB", 1, 0.0, 1, "否", 1, "张三",
//				"张三", 1, 0, "2017-05-22", "2017-05-22");
//		pojo.getPurchaseOutStorageInfos().add(new PurchaseOutStorageInfo("66", "辣辣", "啦啦", "辣", 10, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, "", 0, ""));
//		System.out.println(pojo);
		pojo.setLogicState(1);
		purchaseOutStorageService.update(pojo);
	}
	
	@RequestMapping("delete")
	@ResponseBody
	public void delete(@RequestBody String billNo) {
		System.out.println(billNo);
		String no=billNo.replace("=", "");
		System.out.println(no);
		purchaseOutStorageService.delete(no, 0);
	}
	
	
	@RequestMapping("updateAuditingState")
	@ResponseBody
	public void updateAuditingState(@RequestBody String billNo,@RequestBody int auditingState) {
		System.out.println(billNo+" "+auditingState);
		purchaseOutStorageService.updateAuditingState(billNo,auditingState);
	}
	
	
	@RequestMapping("updateOrderPodNoCountAndPoDk")
	@ResponseBody
	public void updateOrderPodNoCountAndPoDk() {
//		@RequestBody String fromNo,@RequestBody int poDk,@RequestBody int podNoCount
//		System.out.println(fromNo+" "+poDk+" "+podNoCount);
		purchaseOutStorageService.updateOrderPodNoCountAndPoDk("20170525001", 1, 1);
	}
}
